/[admin]/admin2/client/admin_gui.lua

https://gitlab.com/yasin3223/mtasa-resources · Lua · 240 lines · 212 code · 19 blank · 9 comment · 44 complexity · c6ba72a5280b60c4c9797498ada5a42a MD5 · raw file

  1. --[[**********************************
  2. *
  3. * Multi Theft Auto - Admin Panel
  4. *
  5. * client/admin_gui.lua
  6. *
  7. * Original File by lil_Toady
  8. *
  9. **************************************]]
  10. _guiprotected = {}
  11. function guiCreateHeader ( x, y, w, h, text, relative, parent )
  12. local header = guiCreateLabel ( x, y, w, h, text, relative, parent )
  13. if ( header ) then
  14. guiLabelSetColor ( header, 255, 0, 0 )
  15. guiSetFont ( header, "default-bold-small" )
  16. return header
  17. end
  18. return false
  19. end
  20. function guiCreateInnerImage ( image, parent, above )
  21. local sx, sy = guiGetSize ( parent, false )
  22. local img = nil
  23. if ( above ) then
  24. img = guiCreateStaticImage ( 0, 0, 0, 0, image, false, getElementParent ( parent ) )
  25. local px, py = guiGetPosition ( parent, false )
  26. guiSetPosition ( img, px + sx - sy, py, false )
  27. else
  28. img = guiCreateStaticImage ( 0, 0, 0, 0, image, false, parent )
  29. guiSetPosition ( img, sx - sy, 0, false )
  30. end
  31. guiSetSize ( img, sy, sy, false )
  32. return img
  33. end
  34. local _guiCreateWindow = guiCreateWindow
  35. function guiCreateWindow ( ... )
  36. local window = _guiCreateWindow ( ... )
  37. if ( window ) then
  38. guiWindowSetSizable ( window, false )
  39. return window
  40. end
  41. return nil
  42. end
  43. local _guiCreateTab = guiCreateTab
  44. function guiCreateTab ( name, parent, right )
  45. local tab = _guiCreateTab ( name, parent )
  46. if ( tab ) then
  47. if ( right ) then
  48. right = "general.tab_"..right
  49. if ( not hasPermissionTo ( right ) ) then
  50. guiSetEnabled ( tab, false )
  51. _guiprotected[right] = tab
  52. end
  53. end
  54. return tab
  55. end
  56. return false
  57. end
  58. local _guiCreateButton = guiCreateButton
  59. function guiCreateButton ( x, y, w, h, text, relative, parent, right )
  60. local button = _guiCreateButton ( x, y, w, h, text, relative, parent )
  61. if ( button ) then
  62. if ( right ) then
  63. right = "command."..right
  64. if ( not hasPermissionTo ( right ) ) then
  65. guiSetEnabled ( button, false )
  66. _guiprotected[right] = button
  67. end
  68. end
  69. guiSetFont ( button, "default-bold-small" )
  70. return button
  71. end
  72. return false
  73. end
  74. local _guiCreateCheckBox = guiCreateCheckBox
  75. function guiCreateCheckBox ( x, y, w, h, text, checked, relative, parent, right )
  76. local check = _guiCreateCheckBox ( x, y, w, h, text, checked, relative, parent )
  77. if ( check ) then
  78. if ( right ) then
  79. right = "command."..right
  80. if ( not hasPermissionTo ( right ) ) then
  81. guiSetEnabled ( check, false )
  82. _guiprotected[right] = check
  83. end
  84. end
  85. return check
  86. end
  87. return false
  88. end
  89. local guiColorPickers = {}
  90. function guiCreateColorPicker ( x, y, w, h, r, g, b, relative, parent )
  91. local mask = guiCreateLabel ( x, y, w, h, "", relative, parent )
  92. guiLabelSetHorizontalAlign ( mask, "left", true )
  93. guiColorPickers[mask] = { r = r or 255, g = g or 0, b = b or 0 }
  94. addEventHandler ( "onClientGUIClick", mask, function ( key, state )
  95. local info = guiColorPickers[source]
  96. if ( key == "left" and state == "up" and info ) then
  97. local x, y = guiGetAbsolutePosition ( mask )
  98. local sx, sy = guiGetSize ( mask, false )
  99. info.picking = true
  100. info.r, info.g, info.b = aColor.Open ( x + sx, y - 5, info.r, info.g, info.b )
  101. info.picking = nil
  102. end
  103. end )
  104. addEventHandler ( "onClientElementDestroy", mask, function ()
  105. guiColorPickers[source] = nil
  106. end )
  107. end
  108. addEventHandler ( "onClientRender", getRootElement(), function ()
  109. if ( isConsoleActive() ) then
  110. return
  111. end
  112. for mask, info in pairs ( guiColorPickers ) do
  113. if ( guiGetVisible ( mask ) ) then
  114. if ( info.picking ) then
  115. info.r, info.g, info.b = aColor.Color.r, aColor.Color.g, aColor.Color.b
  116. end
  117. local x, y = guiGetAbsolutePosition ( mask )
  118. local sx, sy = guiGetSize ( mask, false )
  119. dxDrawLine ( x, y + sy / 2, x + sx, y + sy / 2, tocolor ( info.r, info.g, info.b, 255 ), sy, true )
  120. end
  121. end
  122. end )
  123. local guiBlendTable = {}
  124. function guiBlendElement ( element, alpha, hide )
  125. local increment = ( alpha - guiGetAlpha ( element ) ) * 10
  126. guiBlendTable[element] = { inc = increment, hide = hide, target = alpha }
  127. end
  128. addEventHandler ( "onClientRender", _root, function ()
  129. for element, v in pairs ( guiBlendTable ) do
  130. local a = guiGetAlpha ( element ) + v.inc / 40
  131. if ( v.inc < 0 and a <= v.target ) then
  132. a = v.target
  133. if ( v.hide ) then guiSetVisible ( element, false ) end
  134. guiBlendTable[element] = nil
  135. elseif ( v.inc > 0 and a >= v.target ) then
  136. a = v.target
  137. guiBlendTable[element] = nil
  138. end
  139. guiSetAlpha ( element, a )
  140. end
  141. end )
  142. function guiCreateContextMenu ( element )
  143. local menu = guiCreateStaticImage ( 0, 0, 100, 0, "client/images/black.png", false )
  144. guiSetVisible ( menu, false )
  145. if ( element ) then
  146. guiSetContextMenu ( element, menu )
  147. end
  148. return menu
  149. end
  150. function guiSetContextMenu ( element, menu )
  151. addEventHandler ( "onClientGUIClick", element, function ( button )
  152. contextSource = source
  153. if ( getElementType ( source ) == "gui-gridlist" and guiGridListGetSelectedItem ( source ) == -1 ) then
  154. return
  155. end
  156. if ( button == "right" ) then
  157. local sx, sy = guiGetScreenSize()
  158. local x, y = getCursorPosition ()
  159. x, y = sx * x, sy * y
  160. guiSetPosition ( menu, x, y, false )
  161. guiSetVisible ( menu, true )
  162. guiBringToFront ( menu )
  163. setTimer ( function ()
  164. addEventHandler ( "onClientClick", getRootElement(), function ( button, state, x, y )
  165. local sx, sy = guiGetSize ( menu, false )
  166. local px, py = guiGetPosition ( menu, false )
  167. if ( x < px or x > px + sx ) or ( y < py or y > py + sy ) then
  168. guiSetVisible ( menu, false )
  169. removeEventHandler ( "onClientClick", getRootElement(), debug.getinfo ( 1, "f" ).func )
  170. end
  171. end )
  172. end, 50, 1 )
  173. end
  174. end, false )
  175. addEventHandler ( "onClientGUIClick", menu, function ( button )
  176. guiSetVisible ( menu, false )
  177. end )
  178. end
  179. function guiContextMenuAddItem ( element, text )
  180. local height = 16
  181. local sx, sy = guiGetSize ( element, false )
  182. local n = #getElementChildren ( element )
  183. local bg = guiCreateStaticImage ( 1, n * height + 1, 0, height, "client/images/black.png", false, element )
  184. local item = guiCreateLabel ( 0, 0, 0, height, " "..text.." ", false, bg )
  185. local extent = guiLabelGetTextExtent ( item )
  186. local width = guiGetSize ( element, false ) - 2
  187. if ( extent > width ) then
  188. width = extent
  189. end
  190. guiSetSize ( element, width + 2, ( n + 1 ) * height + 2, false )
  191. guiSetSize ( bg, width, height, false )
  192. guiSetSize ( item, width, height, false )
  193. addEventHandler ( "onClientMouseEnter", item, function ()
  194. guiStaticImageLoadImage ( getElementParent ( source ), "client/images/blue.png" )
  195. end, false )
  196. addEventHandler ( "onClientMouseLeave", item, function ()
  197. guiStaticImageLoadImage ( getElementParent ( source ), "client/images/black.png" )
  198. end, false )
  199. return item
  200. end
  201. function guiCreateToolTip ( element )
  202. end
  203. function guiGetAbsolutePosition ( element )
  204. local x, y = guiGetPosition ( element, false )
  205. local parent = getElementParent ( element )
  206. while ( parent ~= getResourceGUIElement() ) do
  207. local px, py = guiGetPosition ( parent, false )
  208. x = x + px
  209. y = y + py
  210. parent = getElementParent ( parent )
  211. end
  212. return x, y
  213. end
  214. function guiHandleInput ( element )
  215. addEventHandler ( "onClientGUIFocus", element, function ()
  216. guiSetInputEnabled ( true )
  217. end, false )
  218. addEventHandler ( "onClientGUIBlur", element, function ()
  219. guiSetInputEnabled ( false )
  220. end, false )
  221. end